{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020 ECCV Contrastive Learning for Unpaired Image-to-Image Translation.pdf\n",
      "LICENSE\n",
      "README.md\n",
      "TrainAndTest.ipynb\n",
      "data\n",
      "datasets\n",
      "docs\n",
      "environment.yml\n",
      "experiments\n",
      "imgs\n",
      "models\n",
      "options\n",
      "requirements.txt\n",
      "test.py\n",
      "tox.ini\n",
      "train.py\n",
      "util\n"
     ]
    }
   ],
   "source": [
    "! ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----------------- Options ---------------\n",
      "                 CUT_mode: CUT                           \n",
      "               batch_size: 2                             \t[default: 1]\n",
      "                    beta1: 0.5                           \n",
      "                    beta2: 0.999                         \n",
      "          checkpoints_dir: ./checkpoints                 \n",
      "           continue_train: False                         \n",
      "                crop_size: 256                           \n",
      "                 dataroot: ../middle_cityRH              \t[default: placeholder]\n",
      "             dataset_mode: unaligned                     \n",
      "                direction: AtoB                          \n",
      "              display_env: main                          \n",
      "             display_freq: 400                           \n",
      "               display_id: -1                            \n",
      "            display_ncols: 4                             \n",
      "             display_port: 8097                          \n",
      "           display_server: http://localhost              \n",
      "          display_winsize: 256                           \n",
      "               easy_label: experiment_name               \n",
      "                    epoch: latest                        \n",
      "              epoch_count: 1                             \n",
      "          evaluation_freq: 5000                          \n",
      "        flip_equivariance: False                         \n",
      "                 gan_mode: lsgan                         \n",
      "                  gpu_ids: 0                             \n",
      "                init_gain: 0.02                          \n",
      "                init_type: xavier                        \n",
      "                 input_nc: 3                             \n",
      "                  isTrain: True                          \t[default: None]\n",
      "            lambda_DisNCE: 1.0                           \n",
      "               lambda_GAN: 1.0                           \n",
      "               lambda_NCE: 1.0                           \n",
      "                load_size: 286                           \n",
      "                       lr: 0.0002                        \n",
      "           lr_decay_iters: 50                            \n",
      "                lr_policy: linear                        \n",
      "         max_dataset_size: inf                           \n",
      "                    model: SingleExtractor               \t[default: cutrain]\n",
      "                 n_epochs: 100                           \n",
      "           n_epochs_decay: 100                           \n",
      "               n_layers_D: 3                             \n",
      "                     name: middle_single_ps1             \t[default: experiment_name]\n",
      "                    nce_T: 0.07                          \n",
      "                  nce_idt: True                          \n",
      "nce_includes_all_negatives_from_minibatch: False                         \n",
      "               nce_layers: 0,4,8,12,16                   \n",
      "                      ndf: 64                            \n",
      "                     netD: basic                         \n",
      "                     netF: mlp_sample                    \n",
      "                  netF_nc: 256                           \n",
      "                     netG: resnet_9blocks                \n",
      "                      ngf: 64                            \n",
      "             no_antialias: False                         \n",
      "          no_antialias_up: False                         \n",
      "               no_dropout: True                          \n",
      "                  no_flip: False                         \n",
      "                  no_html: False                         \n",
      "                    normD: instance                      \n",
      "                    normG: instance                      \n",
      "              num_patches: 128                           \n",
      "              num_threads: 4                             \n",
      "                output_nc: 3                             \n",
      "                    phase: train                         \n",
      "                pool_size: 0                             \n",
      "               preprocess: crop                          \n",
      "          pretrained_name: None                          \n",
      "               print_freq: 100                           \n",
      "         random_scale_max: 3.0                           \n",
      "             save_by_iter: False                         \n",
      "          save_epoch_freq: 50                            \n",
      "         save_latest_freq: 5000                          \n",
      "           serial_batches: False                         \n",
      "stylegan2_G_num_downsampling: 1                             \n",
      "                   suffix:                               \n",
      "         update_html_freq: 1000                          \n",
      "                  verbose: False                         \n",
      "----------------- End -------------------\n",
      "dataset [UnalignedDataset] was created\n",
      "model [SINGLEEXTRACTORModel] was created\n",
      "The number of training images = 1401\n",
      "create web directory ./checkpoints/middle_single_ps1/web...\n",
      "THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=421 error=11 : invalid argument\n",
      "---------- Networks initialized -------------\n",
      "[Network G] Total number of parameters : 11.378 M\n",
      "[Network F] Total number of parameters : 0.560 M\n",
      "[Network D] Total number of parameters : 2.765 M\n",
      "-----------------------------------------------\n",
      "(epoch: 1, iters: 100, time: 0.134, data: 0.223) G_GAN: 0.354 D_real: 0.249 D_fake: 0.204 G: 15.760 NCE: 4.666 DisNCE: 10.731 NCE_Y: 4.684 \n",
      "(epoch: 1, iters: 200, time: 0.159, data: 0.002) G_GAN: 0.859 D_real: 0.237 D_fake: 0.385 G: 16.258 NCE: 4.873 DisNCE: 10.544 NCE_Y: 4.838 \n",
      "(epoch: 1, iters: 300, time: 0.180, data: 0.002) G_GAN: 0.443 D_real: 0.116 D_fake: 0.169 G: 15.302 NCE: 4.782 DisNCE: 10.092 NCE_Y: 4.753 \n",
      "(epoch: 1, iters: 400, time: 0.197, data: 0.002) G_GAN: 0.821 D_real: 0.106 D_fake: 0.094 G: 15.695 NCE: 4.786 DisNCE: 10.079 NCE_Y: 4.802 \n",
      "^C\n",
      "Traceback (most recent call last):\n",
      "  File \"train.py\", line 49, in <module>\n",
      "    torch.cuda.synchronize()\n",
      "  File \"/usr/local/lib/python3.6/dist-packages/torch/cuda/__init__.py\", line 348, in synchronize\n",
      "    return torch._C._cuda_synchronize()\n",
      "KeyboardInterrupt\n"
     ]
    }
   ],
   "source": [
    "! python train.py --dataroot ../middle_cityRH --name middle_single_ps1 --model SingleExtractor --batch_size 2 --preprocess crop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[33mWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f494b9f0710>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/packaging/\u001b[0m\n",
      "\u001b[33mWARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f494b9f0518>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/packaging/\u001b[0m\n",
      "\u001b[33mWARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f494b9f04e0>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/packaging/\u001b[0m\n",
      "\u001b[33mWARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f494b9f03c8>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/packaging/\u001b[0m\n",
      "\u001b[33mWARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f494b9f0400>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/packaging/\u001b[0m\n",
      "Collecting packaging\n",
      "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/3e/89/7ea760b4daa42653ece2380531c90f64788d979110a2ab51049d92f408af/packaging-20.9-py2.py3-none-any.whl (40kB)\n",
      "\u001b[K     |################################| 40kB 682kB/s eta 0:00:011\n",
      "\u001b[?25hRequirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from packaging) (2.3.0)\n",
      "Installing collected packages: packaging\n",
      "Successfully installed packaging-20.9\n",
      "\u001b[33mWARNING: You are using pip version 19.3.1; however, version 21.0.1 is available.\n",
      "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "! pip3 install packaging"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----------------- Options ---------------\n",
      "                 CUT_mode: CUT                           \n",
      "               batch_size: 1                             \n",
      "          checkpoints_dir: ./checkpoints                 \n",
      "                crop_size: 256                           \n",
      "                 dataroot: ../middle_cityRH              \t[default: placeholder]\n",
      "             dataset_mode: unaligned                     \n",
      "                direction: AtoB                          \n",
      "          display_winsize: 256                           \n",
      "               easy_label: experiment_name               \n",
      "                    epoch: latest                        \n",
      "                     eval: False                         \n",
      "        flip_equivariance: False                         \n",
      "                  gpu_ids: 0                             \n",
      "                init_gain: 0.02                          \n",
      "                init_type: xavier                        \n",
      "                 input_nc: 3                             \n",
      "                  isTrain: False                         \t[default: None]\n",
      "            lambda_DisNCE: 1.0                           \n",
      "               lambda_GAN: 1.0                           \n",
      "               lambda_NCE: 1.0                           \n",
      "                load_size: 256                           \n",
      "         max_dataset_size: inf                           \n",
      "                    model: SingleExtractor               \t[default: cutrain]\n",
      "               n_layers_D: 3                             \n",
      "                     name: middle_single_ps1             \t[default: experiment_name]\n",
      "                    nce_T: 0.07                          \n",
      "                  nce_idt: True                          \n",
      "nce_includes_all_negatives_from_minibatch: False                         \n",
      "               nce_layers: 0,4,8,12,16                   \n",
      "                      ndf: 64                            \n",
      "                     netD: basic                         \n",
      "                     netF: mlp_sample                    \n",
      "                  netF_nc: 256                           \n",
      "                     netG: resnet_9blocks                \n",
      "                      ngf: 64                            \n",
      "             no_antialias: False                         \n",
      "          no_antialias_up: False                         \n",
      "               no_dropout: True                          \n",
      "                  no_flip: False                         \n",
      "                    normD: instance                      \n",
      "                    normG: instance                      \n",
      "              num_patches: 128                           \n",
      "                 num_test: 600                           \n",
      "              num_threads: 4                             \n",
      "                output_nc: 3                             \n",
      "                    phase: test                          \n",
      "                pool_size: 0                             \n",
      "               preprocess: None                          \t[default: crop]\n",
      "         random_scale_max: 3.0                           \n",
      "              results_dir: ./results/                    \n",
      "           serial_batches: False                         \n",
      "stylegan2_G_num_downsampling: 1                             \n",
      "                   suffix:                               \n",
      "                  verbose: False                         \n",
      "----------------- End -------------------\n",
      "dataset [UnalignedDataset] was created\n",
      "dataset [UnalignedDataset] was created\n",
      "model [SINGLEEXTRACTORModel] was created\n",
      "creating web directory ./results/middle_single_ps1/test_latest\n",
      "THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=421 error=11 : invalid argument\n",
      "loading the model from ./checkpoints/middle_single_ps1/latest_net_G.pth\n",
      "---------- Networks initialized -------------\n",
      "[Network G] Total number of parameters : 11.378 M\n",
      "-----------------------------------------------\n",
      "processing (0000)-th image... ['../middle_cityRH/testA/aachen_000000_000019_leftImg8bit.png']\n",
      "processing (0010)-th image... ['../middle_cityRH/testA/aachen_000089_000019_leftImg8bit.png']\n",
      "processing (0020)-th image... ['../middle_cityRH/testA/bochum_000000_018195_leftImg8bit.png']\n",
      "processing (0030)-th image... ['../middle_cityRH/testA/bremen_000117_000019_leftImg8bit.png']\n",
      "processing (0040)-th image... ['../middle_cityRH/testA/bremen_000261_000019_leftImg8bit.png']\n",
      "processing (0050)-th image... ['../middle_cityRH/testA/cologne_000075_000019_leftImg8bit.png']\n",
      "processing (0060)-th image... ['../middle_cityRH/testA/dusseldorf_000039_000019_leftImg8bit.png']\n",
      "processing (0070)-th image... ['../middle_cityRH/testA/dusseldorf_000204_000019_leftImg8bit.png']\n",
      "processing (0080)-th image... ['../middle_cityRH/testA/hamburg_000000_082187_leftImg8bit.png']\n",
      "processing (0090)-th image... ['../middle_cityRH/testA/hanover_000000_035606_leftImg8bit.png']\n",
      "processing (0100)-th image... ['../middle_cityRH/testA/jena_000086_000019_leftImg8bit.png']\n",
      "processing (0110)-th image... ['../middle_cityRH/testA/monchengladbach_000000_017950_leftImg8bit.png']\n",
      "processing (0120)-th image... ['../middle_cityRH/testA/strasbourg_000000_027233_leftImg8bit.png']\n",
      "processing (0130)-th image... ['../middle_cityRH/testA/strasbourg_000001_022151_leftImg8bit.png']\n",
      "processing (0140)-th image... ['../middle_cityRH/testA/stuttgart_000001_000019_leftImg8bit.png']\n",
      "processing (0150)-th image... ['../middle_cityRH/testA/stuttgart_000123_000019_leftImg8bit.png']\n",
      "processing (0160)-th image... ['../middle_cityRH/testA/ulm_000051_000019_leftImg8bit.png']\n",
      "processing (0170)-th image... ['../middle_cityRH/testA/weimar_000130_000019_leftImg8bit.png']\n"
     ]
    }
   ],
   "source": [
    "! python test.py --dataroot ../middle_cityRH --name middle_single_ps1 --model SingleExtractor --preprocess None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
